//
//  CQPlayer.h
//  Pods
//
//  Created by green on 16/6/19.
//
//
#import <AVFoundation/AVFoundation.h>

/// MARK: - 从后台或别的场景切换回来恢复之前播放状态

typedef NS_ENUM(NSInteger, CQVPWillChangeStatus) {
    CQVPWillChangeStatusPause,// 暂停
      CQVPWillChangeStatusPlaying // 正在播放
};

////////////////////////////////////////////////////////////////
// MARK: - 播放器代理
////////////////////////////////////////////////////////////////

@class CQVideoPlayer;
@protocol CQVideoPlayerDelegate <NSObject>

// 准备资源

- (void)videoPlayerPrepareToLoadAsset:(CQVideoPlayer *)videoPlayer;

// 下载进度

- (void)videoPlayerProgressToLoadAsset:(CQVideoPlayer *)videoPlayer withProgress:(double)progress;

// 准备播放

- (void)videoPlayerPrepareToPlay:(CQVideoPlayer *)videoPlayer;

// 成功播放

- (void)videoPlayerSuccessToPlay:(CQVideoPlayer *)videoPlayer;

// 失败播放

- (void)videoPlayerFailureToPlay:(CQVideoPlayer *)videoPlayer;


@end

////////////////////////////////////////////////////////////////
// MARK: - 播放器资源(实现先下载，后播放)
////////////////////////////////////////////////////////////////

@protocol CQVideoPlayerURLProtocol <NSObject>

@required

- (void)getVideoURL:(void (^)(NSURL *))completion withProgress:(void (^)(double))progress;

@end

////////////////////////////////////////////////////////////////
// MARK: - 播放器
////////////////////////////////////////////////////////////////


/**
 视频播放器
 */
@protocol CQToolBarProtocol;
@interface CQVideoPlayer : NSObject

// 下载对象

@property (strong, nonatomic) id<CQVideoPlayerURLProtocol> videoPlayerURL;

// 异步获取资源

- (id)initWithVideoPlayerURL:(id<CQVideoPlayerURLProtocol>) videoPlayerURL;

// 构造方法

- (id)initWithURL:(NSURL *)assetURL;

// 播放工具栏

@property (weak, nonatomic) UIView<CQToolBarProtocol> *toolBar;

// 代理

@property (weak, nonatomic) id<CQVideoPlayerDelegate> delegate;

// 释放

- (void)free;

//视频标题

@property (strong, nonatomic) NSString *videoTitle;

//系统播放器对象

@property (strong, nonatomic, readonly) AVPlayer *player;

//从后台或别的场景切换回来恢复之前播放状态

@property (assign, nonatomic) CQVPWillChangeStatus willChangeStatus;

// 当前播放时间

@property (assign, nonatomic) NSTimeInterval currentTime;

// 视频总时间

@property (assign, nonatomic) NSTimeInterval totalDuration;

//是否正在播放

-(BOOL)isPlaying;

//播放

-(void)play;


//暂停

-(void)pause;

//停止

-(void)stop;

//开始滑动进度条

-(void)scrubbingDidStart;

//正在滑动进度条

-(void)scrubbedToTime:(NSTimeInterval)time;

//结束滑动进度条

-(void)scrubbingDidEnd;

//调整播放时间

-(void)jumpedToTime:(NSTimeInterval)time;

//获取视频数据

-(CVPixelBufferRef)getPixelBuffer;

@end
